package com.sam;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LogoutGoogle extends ActionSupport {
	
	private static final long serialVersionUID = 2417665506786180784L;
	private String url;
	
	public String execute() {
		Map<String, Object> session = ActionContext.getContext().getSession();
		session.put("usuario", null);
		session.put("afiliadoValido", null);
		
		UserService userService = UserServiceFactory.getUserService();
		HttpServletRequest request = ServletActionContext.getRequest();
		if (request.getUserPrincipal() != null) {
			 setUrl(userService.createLogoutURL("/loginGoogle.action"));
			return "logout";
		}
		
		return SUCCESS;

	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

}
